<template>
  <div class="account-table-wrap">
    <el-table
      :data="tableData"
      style="width: 100%"
      :border="true"
      :fit="true"
      :stripe="true"
      size="mini"
      align="center">
      <el-table-column
      type="selection"
      width="55">
      </el-table-column>

      <el-table-column
        prop="id"
        label="id"
        min-width="100"
        align="center">
      </el-table-column>

      <el-table-column
        prop="number"
        label="配料编号"
        min-width="180"
        align="center">
      </el-table-column>

      <el-table-column
        prop="material_name"
        label="配料名称"
        min-width="180"
        align="center">
      </el-table-column>

      <el-table-column
        prop="formatName"
        label="规格"
        min-width="120"
        align="center">
      </el-table-column>

      <el-table-column
        prop="unit"
        label="单位"
        min-width="120"
        align="center">
      </el-table-column>

      <el-table-column
        prop="price"
        label="供应价"
        min-width="120"
        align="center">
        <template slot-scope="scope">
          <el-button
           v-if="scope.row.price==='0.00'"
            size="mini"
            plain
            type="info"
            @click="priceEdit(scope.row)" v-text="'未设置'"></el-button>
          <div v-else class="check-list" v-text="(scope.row.price)"></div>
        </template>
      </el-table-column>

      <el-table-column label="操作"
      min-width="180"
      align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            plain
            type="primary"
            @click="tableEdit(scope.row)">供应价记录</el-button>
          <el-button
            size="mini"
            plain
            type="danger"
            @click="tableDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <deleteConfirm v-if="showMask" @closeDelete="closeDelete" @deleteConfirm="deleteConfirm"></deleteConfirm>

    <el-dialog class="price" v-if="changPriceShow" :title="priceTitle" center :visible="true" width="400px" @close="priceClose">
        <el-input size="small" class="search" clearable v-model="price" placeholder="请输入单价"></el-input>
        <span slot="footer" class="dialog-footer">
        <el-button @click="priceClose">取 消</el-button>
        <el-button type="primary" @click="priceConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop, Emit } from 'vue-property-decorator';
import deleteConfirm from '@/components/deleteConfirm.vue';
import ajaxResquest from '@/api/apiRequest';
@Component({
  components: {
    deleteConfirm
  }
})
export default class AccountListTable extends Vue {
  @Prop({
    type: Array
  })
  tableData!: any[];
  showMask: boolean = false;
  deleteId!: number;
  deleteRes!: ajaxResquest;
  priceRes!: ajaxResquest;
  changPriceShow: boolean = false;
  priceTitle: string = '';
  price: string = '';
  id: string = '';
  mounted() {
    this.deleteRes = new ajaxResquest('/purchase/delSuppliersFor');
    this.priceRes = new ajaxResquest('/purchase/updateSuppliersForPrice');
  }
  priceEdit(row: any) {
    console.log(row);

    // this.$to('supplierListCreate', { edit: true, id: row.id });
    this.priceTitle = `${row.material_name}  ${row.formatName}  供应价`;
    this.id = row.id;
    this.changPriceShow = true;
  }
  priceClose() {
    this.changPriceShow = false;
  }
  priceConfirm() {
    this.priceRes
      .getFunction({ id: this.id, price: this.price })
      .then((res: any) => {
        if (res.data.code === 1) {
          this.changPriceShow = false;

          this.getData();
        }
      });
  }
  tableDelete(row: any) {
    console.log(row);
    this.deleteId = row.id;
    this.showMask = true;
  }
  closeDelete(row: object) {
    this.showMask = false;
  }
  toSupplierSup(row: any) {
    this.$to('supplierSup', { row: row });
  }
  deleteConfirm() {
    console.log('done');
    this.deleteRes.getFunction({ id: this.deleteId }).then((res:any) => {
      if (res.data.code === 1) {
        this.getData();
        this.showMask = false;
      }
    });
  }
  @Emit('getData')
  getData() {}
}
</script>
<style lang="less">
.account-table-wrap {
  .price {
    .el-dialog__title {
      font-size: 16px;
    }
  }
}
</style>
